# CORS 中间件配置

from fastapi.middleware.cors import CORSMiddleware
from fastapi import FastAPI
from src.config.settings import get_settings


def add_cors_middleware(app: FastAPI):
    """添加CORS中间件"""
    config = get_settings()
    app.add_middleware(
        CORSMiddleware,
        allow_origins=config.CORS_ORIGINS,
        allow_credentials=True,
        allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
        allow_headers=["*"],
        expose_headers=["*"]
    )